<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// MQTT消息处理测试路由 (放在前面，避免路由冲突)
Route::get('/', 'index/Index/index');

// MQTT消息处理测试路由 (放在前面，避免路由冲突)
Route::get('mqtt/test', 'index/MqttTest/testMessageParsing');
Route::get('mqtt/data', 'index/MqttTest/viewData');
Route::get('mqtt/test2', 'index/MqttTest/testSecondDb');
Route::get('mqtt/update', 'index/MqttTest/testUpdateOnly');
Route::get('mqtt/cache', 'index/MqttTest/testCacheOptimization');
Route::get('mqtt/batch', 'index/MqttTest/testBatchOptimization');
Route::get('mqtt/connection', 'index/MqttTest/testConnectionOptimization');
Route::get('mqtt/check', 'index/MqttTest/checkImeiInDatabase');
Route::get('mqtt/debug', 'index/MqttTest/debugDbQuery');
Route::get('mqtt/force', 'index/MqttTest/forceClearCacheAndTest');

// MQTT日志测试路由
Route::get('mqtt/log/test', 'index/MqttLogTest/testLog');
Route::get('mqtt/log/view', 'index/MqttLogTest/viewLogs');
Route::get('mqtt/log/stats', 'index/MqttLogTest/logStats');
Route::get('mqtt/log/clean', 'index/MqttLogTest/cleanOldLogs');

// IMEI调试路由
Route::get('debug/imei/check', 'index/ImeiDebug/checkImei');
Route::get('debug/imei/test-log', 'index/ImeiDebug/testLogSave');
Route::get('debug/imei/logs', 'index/ImeiDebug/recentLogs');
Route::get('debug/imei/simulate', 'index/ImeiDebug/simulateMessage');
Route::get('debug/cache/test', 'index/ImeiDebug/testCache');
Route::get('debug/imei/refresh', 'index/ImeiDebug/refreshImeiCache');
Route::get('debug/redis/check', 'index/ImeiDebug/checkRedis');
Route::get('debug/redis/diagnose', 'index/ImeiDebug/diagnoseRedis');

// API Key管理路由
Route::get('admin/api-key-test/setup', 'admin/ApiKeyTest/setup');
Route::get('admin/api-key-test/generate', 'admin/ApiKeyTest/generate');
Route::get('admin/api-key-test/format', 'admin/ApiKeyTest/format');

// 设备指令下发API（需要API Key验证）
Route::group('api', function () {
    Route::post('device/command', 'api/DeviceCommand/send');
    Route::get('device/commands', 'api/DeviceCommand/getSupportedCommands');
    Route::get('device/command/examples', 'api/DeviceCommand/getExamples');
})->middleware('ApiAuth');

// MQTT路由
Route::get('mqtt', 'mqtt/index');
Route::post('mqtt/publish', 'mqtt/publish');

// 数据库测试路由
Route::get('db/test', 'database/testConnections');
Route::get('db/default', 'database/useDefaultDb');
Route::get('db/second', 'database/useSecondDb');
Route::get('db/cross', 'database/crossDbOperation');
Route::get('db/transaction', 'database/transactionExample');

Route::get('think', function () {
    return 'hello,ThinkPHP5!';
});

// 简单测试路由
Route::get('test', function () {
    return json(['msg' => '路由系统工作正常', 'time' => date('Y-m-d H:i:s')]);
});

// 控制器测试路由
Route::get('test/controller', 'Test/index');
Route::get('test/mqtt', 'Test/mqtt');

// 数据库配置测试路由
Route::get('dbtest/config', 'index/DbTest/testConfig');
Route::get('dbtest/direct', 'index/DbTest/testConnection');
Route::get('dbtest/second', 'index/DbTest/testSecondDb');
Route::get('dbtest/default', 'index/DbTest/testDefaultConnection');
Route::get('dbtest/both', 'index/DbTest/testBothDb');

Route::get('hello/:name', 'index/hello');

return [

];
